package com.igeek;

import com.igeek.boot.config.MyConfig1;
import com.igeek.boot.config.MyConfig3;
import com.igeek.boot.entity.Address;
import com.igeek.boot.entity.Car;
import com.igeek.boot.entity.Person;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Arrays;

/**
 * Hello world!
 *  主启动器
 */

/*
* @SpringBootApplication 复合注解
* 1.@SpringBootConfiguration
*   本质是component  代表IOC容器管理
*
* 2.@EnableAutoConfiguration  开启自动配置
*   2.1@AutoConfigurationPackage
*   2.2@Import({AutoConfigurationImportSelector.class})
*
* 3.@ComponentScan
*   指定扫描包  默认扫描当前启动类同级的包
* */
@SpringBootApplication(/*scanBasePackages = "com.igeek.boot"*/)
public class App 
{
    public static void main( String[] args )
    {
        //创建ioc容器

        ConfigurableApplicationContext ac = SpringApplication.run(App.class, args);
/*        String[] beanDefinitionNames = ac.getBeanDefinitionNames();
        Arrays.stream(beanDefinitionNames)
                .forEach(System.out::println);*/

        System.out.println("---------MyConfig1--------");
        MyConfig1 myConfig1 = ac.getBean(MyConfig1.class);
        System.out.println("myConfig1 = " + myConfig1);
        Person p1 = ac.getBean("pp", Person.class);
        System.out.println("p1 = " + p1);
        Person p2 = ac.getBean("p2", Person.class);
        System.out.println("p2 = " + p2);
        Car car = ac.getBean("car", Car.class);
        System.out.println("car = " + car);

        System.out.println("---------MyConfig2--------");
        String[] beanNamesForType = ac.getBeanNamesForType(Person.class);
        Arrays.stream(beanNamesForType).forEach(System.out::println);
        String[] beanNamesForType1 = ac.getBeanNamesForType(Car.class);
        Arrays.stream(beanNamesForType1).forEach(System.out::println);

        System.out.println("---------MyConfig3--------");
        MyConfig3 myConfig3 = ac.getBean(MyConfig3.class);
        System.out.println("myConfig3 = "+myConfig3);
        Person p3 = ac.getBean("p3", Person.class);
        System.out.println("p3 = " + p3);

        System.out.println("---------MyConfig4--------");
        Address address = ac.getBean(Address.class);
        System.out.println("address = " + address);
    }
}
